package cn.wmw.xyy.service.impl;

import cn.wmw.xyy.domain.MessageBanner;
import cn.wmw.xyy.exception.GlobalExceptionEnum;
import cn.wmw.xyy.mapper.MessageBannerMapper;
import cn.wmw.xyy.service.IMessageBannerService;
import cn.wmw.xyy.utils.AssertUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wmw
 * @since 2023-01-29
 */
@Service
public class MessageBannerServiceImpl extends ServiceImpl<MessageBannerMapper, MessageBanner> implements IMessageBannerService {

    @Override
    public boolean insert(MessageBanner entity) {
        Wrapper<MessageBanner> wrapper = new EntityWrapper<>();
        wrapper.eq("mobile", entity.getMobile());
        MessageBanner messageBanner = selectOne(wrapper);
        AssertUtil.isNull(messageBanner, GlobalExceptionEnum.ERROR);
        entity.setCreateTime(new Date());
        return super.insert(entity);
    }

    @Override
    public MessageBanner selectByPhone(String mobile) {
        Wrapper<MessageBanner> wrapper = new EntityWrapper<>();
        wrapper.eq("mobile", mobile);
        MessageBanner messageBanner = selectOne(wrapper);
        return messageBanner;
    }




}
